/*
 * Copyright (C) 2019 ByteDance Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bytedance.scene.animation.animatorexecutor;

import com.bytedance.scene.Scene;
import com.bytedance.scene.animation.AnimationInfo;
import com.bytedance.scene.animation.NavigationAnimatorExecutor;
import com.bytedance.scene.animation.TransitionUtils;
import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorProperty;
import ohos.agp.components.Component;

/**
 * Created by JiangQi on 8/1/18.
 */
public class HorizontalTransitionAnimatorExecutor extends NavigationAnimatorExecutor {
    @Override
    public boolean isSupport( Class<? extends Scene> from,  Class<? extends Scene> to) {
        return true;
    }

    
    @Override
    protected Animator onPushAnimator(final AnimationInfo fromInfo, final AnimationInfo toInfo) {
        final Component fromView = fromInfo.mSceneView;
        final Component toView = toInfo.mSceneView;
        toView.setTranslationX(toView.getWidth());

        AnimatorProperty fromViewAnimator=new AnimatorProperty();
        fromViewAnimator.setTarget(fromView)
                .moveFromX(0f).moveToX(-fromView.getWidth());

        AnimatorProperty toViewAnimator=new AnimatorProperty();
        toViewAnimator.setTarget(toView)
                .moveFromX(toView.getWidth()).moveToX(0f);

        return TransitionUtils.mergeAnimators(fromViewAnimator, toViewAnimator);
    }

    
    @Override
    protected Animator onPopAnimator(final AnimationInfo fromInfo, final AnimationInfo toInfo) {
        final Component fromView = fromInfo.mSceneView;
        final Component toView = toInfo.mSceneView;
        AnimatorProperty fromViewAnimator=new AnimatorProperty();
        fromViewAnimator.setTarget(fromView)
                .moveFromX(0f).moveToX(fromView.getWidth());

        AnimatorProperty toViewAnimator=new AnimatorProperty();
        toViewAnimator.setTarget(toView)
                .moveFromX(-toView.getWidth()).moveToX(0f);

        return TransitionUtils.mergeAnimators(fromViewAnimator, toViewAnimator);
    }
}
